import 'dart:convert';

class FilterSelectData {
  FilterSelectData(this.code, this.values);

  late String code;
  List<String> values;

  String valueString() {
    String value = "";
    for (String v in values) {
      if (value.isNotEmpty) {
        value += ",";
      }
      value += v;
    }
    return value;
  }

  static String jsonString(List<FilterSelectData> list) {
    Map<String, String> jsonData = {};
    for (FilterSelectData selectData in list) {
      jsonData[selectData.code] = selectData.valueString();
    }
    return json.encode(jsonData);
  }

  factory FilterSelectData.fromJson(Map<String, dynamic> json) =>
      FilterSelectData(json['code'] as String, json['values'] as List<String>);

  Map<String, dynamic> toJson() =>
      <String, dynamic>{'name': code, 'children': values};
}
